package servlet;

import dao.FindAllDao;
import text.leaveBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAllServlet")
public class FindAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

        FindAllDao find = new FindAllDao();
        //防止空指针异常
        List<leaveBean> leaves = find.findAll();

        request.getSession().setAttribute("leaves", leaves);

//        if (leaves != null) {
//            //打印留言
//            for (leaveBean leave: leaves) {
//                System.out.println(leave.getLeave());
//            }
//        }

        response.sendRedirect(request.getContextPath() + "/leaveMessage.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
